package com.hmkj.core.mapper.follow;

import com.hmkj.common.baseMapper.GenericMapper;
import com.hmkj.core.model.follow.FollowRuleModel;
import com.hmkj.core.po.follow.FollowRule;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 跟单规则表相关Dao接口<br>
 *
 * @author bin
 * @date   2017-11-19 01:54:10
 */
public interface FollowRuleMapper extends GenericMapper< FollowRule,Integer> {

    /**
     * 跟单人数
     * @param params
     * @return
     */
    @Select("SELECT COUNT(1) FROM (SELECT COUNT(1) FROM biz_follow_rule t WHERE 1 = 1 AND t.del_flag = #{delFlag} AND t.follow_id = #{followId} AND t.`status` = #{status} GROUP BY t.user_id) t1")
    Integer selcetCountByFollowId(Map<String, Object> params);

    /**
     * 前台查我的跟单
     * @param params
     * @return
     */
    @Select("SELECT COUNT(1) FROM biz_follow_rule t LEFT JOIN biz_user fu ON fu.id = t.follow_id " +
            " LEFT JOIN fm_account account  ON account.user_id = t.user_id WHERE t.del_flag = #{delFlag} AND t.user_id = #{userId} AND t.`status` = #{status}")
    Integer findCountForFollowRuleList(Map<String, Object> params);

    /**
     * 前台查我的跟单
     * @param params
     * @return
     */
    @Select("SELECT t.*, fu.user_name AS 'fu.userName',account.available AS 'account.available' FROM biz_follow_rule t LEFT JOIN biz_user fu ON fu.id = t.follow_id " +
            " LEFT JOIN fm_account account  ON account.user_id = t.user_id WHERE t.del_flag = #{delFlag} AND t.user_id = #{userId} AND t.`status` = #{status} ORDER BY t.create_time DESC")
    List<FollowRuleModel> findListForFollowRuleList(Map<String, Object> params);


}
